﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
using System.Reflection;
using System.ComponentModel;

namespace MetadataBasedConfigArch.Framework
{ 
    public static class ObjectExtensions
    {
        public static object GetPropertyValue(this object entity, String propertyName)
        {
            PropertyInfo propertyInfo = entity.GetType().GetProperty(propertyName);
            if (propertyInfo != null)
            {
                return propertyInfo.GetValue(entity, null);
            }
            return null;
        }

        public static void SetPropertyValue(this object entity, string propertyName, object propertyValue)
        {
            PropertyInfo propertyInfo = entity.GetType().GetProperty(propertyName);
            if (propertyInfo != null)
            {
                propertyInfo.SetValue(entity, propertyValue, null);
            }
        }

        public static T Excute<TExcutor, T>(this TExcutor excutor, Func<TExcutor, T> func)
        {
            return func(excutor);
        }
         
    }
}
